﻿using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_ExamLevel_Select : BaseForm
    {
        ServiceBase service = new ServiceBase();
        string SpecialityKindsNO = string.Empty;
        public Base_ExamLevel_Select(string strSpecialityKindsNO)
        {
            InitializeComponent();
            SpecialityKindsNO = strSpecialityKindsNO;
            Dictionary<string, string> dicExamLevel = Utility.Const.ConstExamLevel.DicExamLevel;
            dicExamLevel.Remove("0");
            lst_ExamLevel.DisplayMember = "Value";
            lst_ExamLevel.ValueMember = "Key";
            lst_ExamLevel.DataSource = dicExamLevel.ToList();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            var selectItems = lst_ExamLevel.SelectedItems;
            if (selectItems != null)
            {
                List<TB_Sys_SpecialityLevelMapping> list = new List<TB_Sys_SpecialityLevelMapping>();
                foreach (var items in selectItems)
                {
                    KeyValuePair<string, string> keyValue = (KeyValuePair<string, string>)items;
                    TB_Sys_SpecialityLevelMapping model = new TB_Sys_SpecialityLevelMapping();
                    model.ExamLevelNO = keyValue.Key;
                    model.ExamLevelName = keyValue.Value;
                    model.SpecialityKindsNO = SpecialityKindsNO;
                    list.Add(model);
                }
                if (service.SaveSpecialityLevelMapping(list))
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            else
            {
                DevHelper.ShowInfoMessageBox("请先选择考试级别!");
            }
        }
    }
}
